//
//  RegisterViewController.m
//  HappyBug
//
//  Created by liulei on 2018/11/5.
//  Copyright © 2018年 www.hc.com.cn. All rights reserved.
//
#import "RegistView.h"
#import "RegisterViewController.h"
#import "InputMessageViewController.h"
#define  WHITH   [UIScreen mainScreen].bounds.size.width
#define  HEIGHT  [UIScreen mainScreen].bounds.size.height
#import "AlertView.h"
@interface RegisterViewController (){
    
    RegistView *registView;
    
    UITextField *nameField;
}

@end

@implementation RegisterViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];

    UIImage *lrightimage=[UIImage imageNamed:@"tabbar_icon_found_normal"];
    UIButton *button2 =[[UIButton alloc]init];
    [button2 addTarget:self action:@selector(backmain) forControlEvents:UIControlEventTouchUpInside];
    [button2 setBackgroundImage:lrightimage forState:UIControlStateNormal];
    UIBarButtonItem *item2 =[[UIBarButtonItem alloc]initWithCustomView:button2];
    self.navigationItem.title=@"个人信息注册";
    //只能设置items
    self.navigationItem.leftBarButtonItem=item2;

    CGRect rectOfNavigationbar = self.navigationController.navigationBar.frame;
    //RegistView
    
    CGRect rectOfStatusbar = [[UIApplication sharedApplication] statusBarFrame];
    NSUInteger hei =  self.navigationController.navigationBar.frame.size.height;
    registView=[[RegistView alloc]initWithFrame:CGRectMake(0, hei+rectOfStatusbar.size.height+2, WHITH, HEIGHT)];
    
    //1
    UITapGestureRecognizer *gest1 =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(FirstFildClick1)];;
    
    [registView.txtLineView addGestureRecognizer:gest1];
    
    //2
   UITapGestureRecognizer *gest2 =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(FirstFildClick2)];;

    [registView.txtLineView2 addGestureRecognizer:gest2];
    
    //3
    UITapGestureRecognizer *gest3 =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(FirstFildClick3)];;
    
    [registView.txtLineView3 addGestureRecognizer:gest3];
    //4
    UITapGestureRecognizer *gest4 =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(FirstFildClick4)];;
    
    [registView.txtLineView4 addGestureRecognizer:gest4];
    //5
    UITapGestureRecognizer *gest5 =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(FirstFildClick5)];;
    
    [registView.txtLineView5 addGestureRecognizer:gest5];
   
    
    [self.view addSubview:registView];

}
-(void)FirstFildClick1{
    InputMessageViewController *nameController =[[InputMessageViewController alloc]init];
    UINavigationController *NameNavController=[[UINavigationController alloc]initWithRootViewController:nameController];
    
  [self presentViewController:NameNavController animated:YES completion:nil];
    
}
//回显输入的名字
-(void)viewWillAppear:(BOOL)animated{
    NSString *inputTXT=  [[NSUserDefaults standardUserDefaults] objectForKey:@"TXTVALUE"];
    registView.labeltxt1.text=inputTXT;

}
-(void)FirstFildClick2{
    AlertView *alert=[[AlertView alloc]initWithFrame:CGRectMake(0, WHITH/2,WHITH/2, 50)];
    [alert showAlert];
    NSLog(@"2");

}
-(void)FirstFildClick3{
    NSLog(@"3");

}
-(void)FirstFildClick4{
    NSLog(@"4");

}
-(void)FirstFildClick5{
    NSLog(@"5");

}

-(void)backmain{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(void)initTextFild{
    
}

//沙盒获取
- (UIImage *)getImageWithjImageName:(NSString *)imageName {
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    
    NSString *filePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:
                          imageName];
    // 保存文件的名称
    UIImage *img = [UIImage imageWithContentsOfFile:filePath];
    NSLog(@"=== %@", img);
    
    return img;
    
}

-(void)imageClick:(id)sender{
    /**
     *  弹出提示框
     */
    //初始化提示框
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    //按钮：拍照，类型：UIAlertActionStyleDefault
    [alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
        /**
         其实和从相册选择一样，只是获取方式不同，前面是通过相册，而现在，我们要通过相机的方式
         */
        UIImagePickerController *PickerImage = [[UIImagePickerController alloc]init];
        //获取方式:通过相机
        PickerImage.sourceType = UIImagePickerControllerSourceTypeCamera;
        PickerImage.allowsEditing = YES;
        PickerImage.delegate = self;
        [self presentViewController:PickerImage animated:YES completion:nil];
    }]];
    
    //按钮：从相册选择，类型：UIAlertActionStyleDefault
    [alert addAction:[UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //初始化UIImagePickerController
        UIImagePickerController *PickerImage = [[UIImagePickerController alloc]init];
        //获取方式1：通过相册（呈现全部相册），UIImagePickerControllerSourceTypePhotoLibrary
        //获取方式2，通过相机，UIImagePickerControllerSourceTypeCamera
        //获取方法3，通过相册（呈现全部图片），UIImagePickerControllerSourceTypeSavedPhotosAlbum
        PickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        //允许编辑，即放大裁剪
        PickerImage.allowsEditing = YES;
        //自代理
        PickerImage.delegate = self;
        //页面跳转
        [self presentViewController:PickerImage animated:YES completion:nil];
    }]];
    //按钮：取消，类型：UIAlertActionStyleCancel
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    
    [self presentViewController:alert animated:YES completion:nil];
    
}

//沙盒保存
- (void)saveImage:(UIImage *)image ImageName:(NSString *)imageName {
    NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    
    
    NSString *filePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:
                          imageName];  // 保存文件的名称
    
    BOOL result =[UIImagePNGRepresentation(image)writeToFile:filePath   atomically:YES]; // 保存成功会返回YES
    if (result == YES) {
        NSLog(@"保存成功");
    }
    
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    //定义一个newPhoto，用来存放我们选择的图片。
    UIImage *newPhoto = [info objectForKey:@"UIImagePickerControllerEditedImage"];
    NSLog(@"newPhoto :%@",newPhoto);
    [self dismissViewControllerAnimated:YES completion:nil];
        
    [self saveImage:newPhoto ImageName:@"head.png"];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
